package com.visionblue.business.ship.print

import android.content.Context
import android.print.PrinterInfo
import androidx.room.Room
import com.visionblue.business.ship.BuildConfig
import com.visionblue.business.ship.model.bean.local.PrintInfo
import com.visionblue.business.ship.model.repository.db.AppDatabase

/**
 * @author: xlh
 * @date: 2020-06-17 6:38 PM
 * @desc:
 */
class PrintManager private constructor(context: Context) {

    private val printer: IPrinter =
        if (BuildConfig.DEBUG) UsbSerialPrinter(context) else UsbPrinter(context)

    /**
     * 打印机是否处于空闲状态
     */
    fun isIdle(): Boolean {
        return true
    }

    /**
     * 开始打印
     */
    fun startPrint(printInfo: PrintInfo) {
//        printer.print(E9LPrintFormat().toBytes(printInfo))
        printer.print(E9LTicketPrintFormat().toBytes(printInfo))
    }

    companion object {
        @Volatile
        private var INSTANCE: PrintManager? = null

        fun getInstance(context: Context): PrintManager {
            return INSTANCE ?: synchronized(this) {
                INSTANCE = PrintManager(context)
                INSTANCE!!
            }
        }
    }
}